package org.yx.service.sqcm.delete_defective_code;

import org.yx.exception.BizException;
import org.yx.models.SqcmDftCod;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 删除不良代码定义
 * 
 * @author zxw
 * @since 2019/05/30
 **/
public class SqcmDeleteDefectiveCodeService extends BaseService {
	public SqcmDeleteDefectiveCodeOut deleteDefectiveCode(SqcmDeleteDefectiveCodeIn in) throws Exception {
		if (StrUtil.isBlank(in.getId())) {
			throw new BizException("SYS-0004", FieldMap.of("parameter", "id"));
		}

		SqcmDftCod dftCode = selectOneLocked(SqcmDftCod.class, in.getId());
		if (dftCode == null || dftCode.getStatus() == 'D') {
			throw new BizException("SQCM-0003", "不良代码数据不存在或已删除。");
		}

		dftCode.setStatus('D');

		update(dftCode, "status");

		SqcmDeleteDefectiveCodeOut out = new SqcmDeleteDefectiveCodeOut();

		return out;
	}
}